using System;
using FluentIoC.Interfaces;

namespace FluentIoC.Configuration
{
    public class Conventions : IConventions
    {
        public Predicate<Type> TypeConventions { get; set; }
        public Predicate<Type> ServiceConventions { get; set; }
        public Predicate<Type> ComponentConventions { get; set; }
        public Predicate<Type> FactoryConventions { get; set; }

        public bool IsValidType(Type allTypes)
        {
            return Validate(TypeConventions, allTypes);
        }

        public bool IsValidServiceType(Type serviceType)
        {
            return Validate(ServiceConventions,serviceType);
        }

        public bool IsValidFactoryType(Type factoryType)
        {
            return Validate(FactoryConventions, factoryType);
        }

        public bool IsValidComponentType(Type componentType)
        {
            return Validate(ComponentConventions, componentType);
        }

        private static bool Validate(Predicate<Type> convention, Type type)
        {
            if(convention != null)
            {
                return convention(type);
            }

            return true;
        }
    }
}